package thread.dn;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class ThreadPoolDemo01 {
    public static void main(String[] args) throws InterruptedException, ExecutionException {

        ExecutorService es = Executors.newFixedThreadPool(4);
        System.out.println(es.getClass().getName());

        es.execute(() -> {
            System.out.println(Thread.currentThread().getName() + ":task1");
        });
        es.execute(() -> {
            System.out.println(Thread.currentThread().getName() + ":task2");
        });
        es.execute(() -> {
            System.out.println(Thread.currentThread().getName() + ":task3");
        });
        es.execute(() -> {
            System.out.println(Thread.currentThread().getName() + ":task4");
        });
        es.execute(() -> {
            System.out.println(Thread.currentThread().getName() + ":task5");
        });

        Future<Integer> res=es.submit(() -> {
            System.out.println(Thread.currentThread().getName() + ": execute task4");
            Thread.sleep(5000);
            return Integer.valueOf("123456");
        });
        System.out.println(res.get());
        es.shutdown();
    }
}
